Require One
Load the first package found from the given array.
Install
Method | Installation |
---|
npm | npm install require-one --save |
component | component install robloach/require-one |
Composer | composer require require-one |
Bower | bower install require-one |
Usage
This works across CommonJS/node, AMD and with global variables for the browser.
CommonJS
This is an example of loading either jQuery, Zepto, or Cheerio with a CommonJS module loader, like Node.js.
var $ = requireOne('jquery', 'zepto', 'cheerio');
AMD
This is an example of loading either jQuery, Zepto, or Cheerio with an AMD module loader, like Require.js.
require(['require-one'], function(requireOne) {
var $ = requireOne('jquery', 'zepto', 'cheerio');
});
Globals
This is an example of loading either jQuery, Zepto, or Cheerio without a module loader, i.e. with the browser's global variables.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="path/to/require-one.js"></script>
<script>
var $ = requireOne('jquery', 'jQuery', 'zepto', 'Zepto', 'cheerio');
</script>
</head>
<body>
<h1>My Sample Project</h1>
</body>
</html>
License
MIT